package com.mit.web.util
{
	import com.mit.web.config.Constants;
	import com.mit.web.config.DisplayConfiguration;
	
	import flash.display.Sprite;
	
	import mx.controls.Alert;
	import mx.messaging.messages.ErrorMessage;
	import mx.resources.ResourceBundle;
	import mx.resources.ResourceManager;
	import mx.rpc.events.FaultEvent;
	
	public class MessageUtil
	{
		
		public function MessageUtil()
		{			
		}
		

		
		public static function popNoRecordMessage(location:Sprite):void{
			var msg:String = ResourceManager.getInstance().getString(Constants.BUNDLE_COMMON,"info.common.norecord");
			var title:String = ResourceManager.getInstance().getString(Constants.BUNDLE_COMMON,"label.message.info");
			Alert.show(msg, title, Alert.YES, location);

		}
		
		public static function popFatalError(msg:String, location:Sprite):void{
			var msg:String = ResourceManager.getInstance().getString(Constants.BUNDLE_COMMON,"error.common.fatalerror",[msg]);
			var title:String = ResourceManager.getInstance().getString(Constants.BUNDLE_COMMON,"label.message.error");
			Alert.show(msg, title, Alert.YES, location);	
		}
		
		public static function popSystemInfo(msg:String, location:Sprite):void{
			var title:String = ResourceManager.getInstance().getString(Constants.BUNDLE_COMMON,"label.message.info");
			Alert.show(msg, title, Alert.YES, location);	
		}
		
		public static function popBackEndError(event:FaultEvent, location:Sprite):void{
			var error:ErrorMessage = event.message as ErrorMessage;
			var title:String = ResourceManager.getInstance().getString(Constants.BUNDLE_COMMON,"label.message.error");
			var msg :String;
			var detail:String;
			if(error == null){
				msg = event.fault.faultString;
				detail = event.fault.faultDetail;
			}else{
				var rootCause:Object = error.rootCause;
				if(rootCause == null ){
					msg = error.faultString;
					detail = error.faultDetail;
				}else{
					if(rootCause.bundle){
					msg = ResourceManager.getInstance().getString(
						rootCause.resource, rootCause.bundle, rootCause.arguments);
					detail = rootCause.message;
					}else{
						msg = rootCause.faultString;
						detail = rootCause.faultDetail;
					}
				}
			}
			
			
		
			if(DisplayConfiguration.getInstance().SHOW_ERROR && detail != null ){
				msg += "\r\n Details:";
				msg += detail;
			}
			Alert.show(msg, title, Alert.YES, location);	
		}
	}
}